#ifndef UTIL_H_
#define UTIL_H_

#include <cmath>
#include <cstdlib>
#include <fstream>

namespace Util
{
	
	double GetDistance( double, double, double, double );
	int RoundToPower( int, int );
	bool DoesFileExist( const char * );
	int random( int min, int max );
	std::string GetFileContents( std::string );
	
};


class Vector2D
{

public:

	double x, y, z;
	
	Vector2D()
	{
	
		x = 0.0;
		y = 0.0;
		z = 0.0;
		
	}
	
	inline void ToInt()
	{
		
		x = ( int )x;
		y = ( int )y;
		z = ( int )z;
		
	}

	inline void SetXY( double vx, double vy )
	{

		x = vx;
		y = vy;
	
	}

	inline void SetXYZ( double vx, double vy, double vz )
	{

		x = vx; 
		y = vy; 
		z = vz;
	
	}
	
	inline double Distance( const Vector2D & v )
	{
		
		return Util::GetDistance( x, y, v.x, v.y );
		
	}
	
	inline double Magnitude()
	{
		
		return sqrt( x * x + y * y + z * z );
		
	}
	
	inline void GetNormal( Vector2D * v )
	{
		
		double m = Magnitude();
		
		v->x /= m;
		v->y /= m;
		v->z /= m;
		
	}
	
	inline void Normalize()
	{
		
		GetNormal( this );
		
	}
	
	inline double DotProduct( Vector2D * v )
	{
		
		return ( x * v->x + y * v->y + z * v->z );
		
	}

	
	inline Vector2D operator- ( Vector2D v2 )
	{
	
		Vector2D v;
		
		v.x = x - v2.x;
		v.y = y - v2.y;
		v.z = z - v2.z;
		
		return v;
		
	}
	
	inline Vector2D operator+ ( Vector2D v2 )
	{
	
		Vector2D v;
		
		v.x = x + v2.x;
		v.y = y + v2.y;
		v.z = z + v2.z;
		
		return v;
		
	}
	
	inline Vector2D operator* ( double d )
	{
		
		Vector2D v;
		
		v.x = x * d;
		v.y = y * d;
		v.z = z * d;
		
		return v;
		
	}
	
	
	inline Vector2D operator-= ( Vector2D & v2 )
	{
		
		x -= v2.x;
		y -= v2.y;
		z -= v2.z;
		
		return *this;
		
	}
	
	inline Vector2D operator+= ( Vector2D & v2 )
	{
	
		x += v2.x;
		y += v2.y;
		z += v2.z;
		
		return *this;
		
	}
	
	inline Vector2D operator*= ( double d )
	{
	
		x *= d;
		y *= d;
		z *= d;
		
		return *this;
		
	}

};


#endif
